# pyecharts的学习和练习

from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.globals import ChartType, SymbolType
from pyecharts.faker import Faker


# todo 01 学习Geo地理坐标
# * add_schema 初始化设置一张地图
def geo01():
    geo = Geo()
    geo.add_schema(maptype="china")
    # 设置地图的名字
    geo.set_global_opts(title_opts=opts.TitleOpts(title="瑞士"))
    # 生成地图
    geo.render(path=r"./Exercise/2021-01-23/geo01.html")


def geo02():
    geo = Geo()
    geo.add_schema(maptype="china", itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111"))
    # 添加点
    geo.add("", [("广州", 55), ("北京", 66), ("杭州", 77), ("重庆", 88)], type_=ChartType.EFFECT_SCATTER, color="white",)
    geo.add(
        "geo",
        [("广州", "上海"), ("广州", "北京"), ("广州", "杭州"), ("广州", "重庆")],
        # 样式是线
        type_=ChartType.LINES,
        # 设置地点的想水纹波动、波动6个圈、指向该点走势的颜色是蓝色
        effect_opts=opts.EffectOpts(
            symbol=SymbolType.ARROW, symbol_size=6, color="blue"
        ),
        # 指向该点的线由0.2的弧度
        linestyle_opts=opts.LineStyleOpts(curve=0.2),
    )
    # 设置这条线的“从A到B的线路名称”是否显示
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(title_opts=opts.TitleOpts(title="Geo-Lines-background"))
    geo.render(path=r"./Exercise/2021-01-23/geo02.html")


def geo03():
    geo = Geo()
    geo.add_schema(maptype="china")
    # 后面是个随机的地点和随机的数值的一个列表
    geo.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
    geo.set_global_opts(
        # is_piecewise 是否分段 
        visualmap_opts=opts.VisualMapOpts(is_piecewise=True, max_=200, min_=100),
        title_opts=opts.TitleOpts(title="Geo-VisualMap（分段型）"),
    ) 
    geo.render(path=r"./Exercise/2021-01-23/geo03.html")


def geo04():
    geo = Geo()
    geo.add_schema(maptype="china")
    geo.add(
        "geo",
        [list(z) for z in zip(Faker.provinces, Faker.values())],
        # 启用热力图效果
        type_=ChartType.HEATMAP,
    )
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(
        visualmap_opts=opts.VisualMapOpts(),
        title_opts=opts.TitleOpts(title="Geo-HeatMap"),
    )
    geo.render(path=r"./Exercise/2021-01-23/geo04.html")


geo01()
geo02()
geo03()
geo04()